package com.bootdo.xzl.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.xzl.domain.EntrustmentInfoDO;
import com.bootdo.xzl.service.EntrustmentInfoService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 委托信息管理
 * 
 * @author chenhuan
 * @email huan.chen@i-soft.com.cn
 * @date 2019-12-17 10:23:44
 */
 
@Controller
@RequestMapping("/xzl/entrustmentInfo")
public class EntrustmentInfoController {
	@Autowired
	private EntrustmentInfoService entrustmentInfoService;
	
	@GetMapping()
	@RequiresPermissions("xzl:entrustmentInfo:entrustmentInfo")
	String EntrustmentInfo(){
	    return "xzl/entrustmentInfo/entrustmentInfo";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("xzl:entrustmentInfo:entrustmentInfo")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<EntrustmentInfoDO> entrustmentInfoList = entrustmentInfoService.list(query);
		int total = entrustmentInfoService.count(query);
		PageUtils pageUtils = new PageUtils(entrustmentInfoList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("xzl:entrustmentInfo:add")
	String add(){
	    return "xzl/entrustmentInfo/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("xzl:entrustmentInfo:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		EntrustmentInfoDO entrustmentInfo = entrustmentInfoService.get(id);
		model.addAttribute("entrustmentInfo", entrustmentInfo);
	    return "xzl/entrustmentInfo/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	//@RequiresPermissions("xzl:entrustmentInfo:add")
	public R save( EntrustmentInfoDO entrustmentInfo){
		if(entrustmentInfoService.save(entrustmentInfo)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("xzl:entrustmentInfo:edit")
	public R update( EntrustmentInfoDO entrustmentInfo){
		entrustmentInfoService.update(entrustmentInfo);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("xzl:entrustmentInfo:remove")
	public R remove( Integer id){
		if(entrustmentInfoService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("xzl:entrustmentInfo:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		entrustmentInfoService.batchRemove(ids);
		return R.ok();
	}
	
	
	
	/**
	 *查询总记录数
	 */
	@GetMapping( "/count")
	@ResponseBody
	//@RequiresPermissions("xzl:entrustmentInfo:entrustmentInfo")
	public int count(){
		
		return entrustmentInfoService.count();
	}
}
